<?php

/**
 * ProjectTree actions.
 *
 * @package    time-tracker
 * @subpackage ProjectTree
 * @author     Carlo Di Fulco
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ProjectTreeActions extends sfActions
{
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeIndex(sfWebRequest $request)
	{
		$this->forward('default', 'module');
	}

	/**
	 *
	 * @extdirect-enable
	 * @extdirect-len 2
	 *
	 */
	public function executeGetTree()
	{

		$raw = $this->getRequestParameter('_raw');

		try {
			switch($raw[1]){
				
				case 'project' : 
					$projectId = explode('-', $raw[0]);
					$projectId = $projectId[1];  
					$this->result = TtTask::getAllAsNodes($projectId, true);
				break; 
				
				default : 
					$this->result = TtProject::getAllAsNodes(false);
			}	
		} catch (Exception $e) {
			$this->result = array(
					'success'	=> false, 
					'msg'		=> $e->getMessage()
			); 
		}
		
		
		return sfView::SUCCESS;

	}

}
